#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdio.h>
#include<string.h>
int main()
{
        int fd;
        unsigned char i, j=10; /* The value written to kernel */
        /* Open the device */
        printf("opening port B!\n");
        if ( (fd = open("/dev/labjack1portB", O_RDWR)) == -1) {
                perror("open");
                return -1;
        }
        printf("portB opened\n");
        sleep(20);
        /* Read the syscall_val value from kernel and printed out */
        printf("Start reading portB\n");
        if(read( fd, (void*) &i, 1) <= 0) {
                perror("read");
                return -1;
        }
        printf("portB read returned\n");
        printf("The return value from port B is %u seconds\n", i);
	sleep(1);

        printf("Start reading portB\n");
        if(read( fd, (void*) &i, 1) <= 0) {
                perror("read");
                return -1;
        }
        printf("portB read returned\n");
        printf("The return value from port B is %u seconds\n", i);
	
	sleep(1);


        printf("Start reading portB\n");
        if(read( fd, (void*) &i, 1) <= 0) {
                perror("read");
                return -1;
        }
        printf("portB read returned\n");
        printf("The return value from port B is %u seconds\n", i);

	sleep(1);

	
        printf("Start reading portB\n");
        if(read( fd, (void*) &i, 1) <= 0) {
                perror("read");
                return -1;
        }
        printf("portB read returned\n");
        printf("The return value from port B is %u seconds\n", i);

        printf("Start write to portB\n");
        if(write( fd, (void*) &j, 1) <= 0) {
                perror("write");
                return -1;
        }
        printf("portB write returned\n");
        while (1) {};
        printf("Start closing portB\n");
        if(close( fd) <= 0) {
                perror("close");
                return -1;
        }
        printf("portB closed\n");
        return 0;

}
